/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BSP_H
#define __BSP_H

/* Includes ------------------------------------------------------------------*/
#include "stm32g0xx_hal.h"

#include "stm32g0xx_ll_iwdg.h"
#include "stm32g0xx_ll_i2c.h"
#include "stm32g0xx_ll_rtc.h"
#include "stm32g0xx_ll_usart.h"
#include "stm32g0xx_ll_rcc.h"
#include "stm32g0xx_ll_bus.h"
#include "stm32g0xx_ll_cortex.h"
#include "stm32g0xx_ll_system.h"
#include "stm32g0xx_ll_utils.h"
#include "stm32g0xx_ll_pwr.h"
#include "stm32g0xx_ll_gpio.h"
#include "stm32g0xx_ll_dma.h"
#include "stm32g0xx_ll_tim.h"
#include "stm32g0xx_ll_exti.h"

#include <stdio.h>

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* Private defines -----------------------------------------------------------*/
#define LED_On                 0
#define LED_Off                1

#define LED3_Pin               GPIO_PIN_6
#define LED3_GPIO_Port         GPIOB
#define LED3(x)                x?(LED3_GPIO_Port->BSRR = (uint32_t)LED3_Pin):(LED3_GPIO_Port->BRR = (uint32_t)LED3_Pin)
#define LED3_Toggle()          HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin)

#define LED2_Pin               GPIO_PIN_4
#define LED2_GPIO_Port         GPIOB
#define LED2(x)                x?(LED2_GPIO_Port->BSRR = (uint32_t)LED2_Pin):(LED2_GPIO_Port->BRR = (uint32_t)LED2_Pin)
#define LED2_Toggle()          HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin)

#define LED1_Pin               GPIO_PIN_5
#define LED1_GPIO_Port         GPIOB
#define LED1(x)                x?(LED1_GPIO_Port->BSRR = (uint32_t)LED1_Pin):(LED1_GPIO_Port->BRR = (uint32_t)LED1_Pin)
#define LED1_Toggle()          HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin)

#define SW1_Pin                GPIO_PIN_14
#define SW1_GPIO_Port          GPIOB
#define SW1()                  (SW1_GPIO_Port->IDR & SW1_Pin)

#define SW2_Pin                GPIO_PIN_15
#define SW2_GPIO_Port          GPIOB
#define SW2()                  (SW2_GPIO_Port->IDR & SW2_Pin)

#define SW3_Pin                GPIO_PIN_8
#define SW3_GPIO_Port          GPIOA
#define SW3()                  (SW3_GPIO_Port->IDR & SW3_Pin)

#define SW4_Pin                GPIO_PIN_9
#define SW4_GPIO_Port          GPIOA
#define SW4()                  (SW4_GPIO_Port->IDR & SW4_Pin)

#define SW5_Pin                GPIO_PIN_6
#define SW5_GPIO_Port          GPIOC
#define SW5()                  (SW5_GPIO_Port->IDR & SW5_Pin)

#define SW6_Pin                GPIO_PIN_7
#define SW6_GPIO_Port          GPIOC
#define SW6()                  (SW6_GPIO_Port->IDR & SW6_Pin)

//#define SW_GPIO_Port           GPIOA
//#define SW_Read()              (((~(SW_GPIO_Port->IDR)) & 0x00FCu)>>2)

typedef struct
{
	const char ver[24];
	const char bdata[32];
}Sys_VersionType;

typedef struct
{
	volatile uint8_t  year;  /* 0~99 */
	volatile uint8_t  month;
	volatile uint8_t  day;
	volatile uint8_t  hour;
	volatile uint8_t  minute;
	volatile uint8_t  second;
	volatile uint32_t allsec;
}Sys_DataTimeType;

extern Sys_DataTimeType Sys_Runtime;
extern Sys_DataTimeType Sys_Adjtime;

extern void SysHal_Init(void);
extern void Sys_GetDataTime(void);
extern void Sys_SetDataTime(void);

extern void Sys_RunLed(void);

extern uint8_t SW_Read(void);

#endif /* __BSP_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
